package com.sanyang.logistics.zhd.handler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sanyang.logistics.pojo.DriverDim;
import com.sanyang.logistics.pojo.OwnerTypeDim;
import com.sanyang.logistics.pojo.Product;
import com.sanyang.logistics.pojo.Schedule;
import com.sanyang.logistics.pojo.ThirdParty;
import com.sanyang.logistics.pojo.TruckDim;
import com.sanyang.logistics.zhd.service.ScheduleService;

@Controller
@RequestMapping("/schedule")
public class ScheduleHandler {
	@Autowired
	private ScheduleService scheService;

	//查询调度
	@RequestMapping("/getAllSchedule")
	@ResponseBody
	public Object getAllSchedule(){
		List<Schedule> allSchedule = scheService.getAllSchedule();
		return allSchedule;
	}


	//查询车辆类型下拉框
	@RequestMapping("/getAllTrucktype")
	@ResponseBody
	public Object getAllTrucktype(){
		List<TruckDim> truckDims = scheService.getAllTrucktype();
		return truckDims;
	}

	//	查询车辆信息
	@RequestMapping("/getAllTruck")
	@ResponseBody
	public Object getAllTruck(TruckDim truckDim){
		System.out.println(truckDim.getLicense());
		List<TruckDim> truckDims = scheService.getAllTruck(truckDim);
		return truckDims;
	}


	//	查询所有者下拉框
	@RequestMapping("/getAllOname")
	@ResponseBody
	public Object getAllOname(TruckDim truckDim){
		List<OwnerTypeDim> truckDims = scheService.getAllOname();
		return truckDims;
	}

	//查询司机信息
	@RequestMapping("/getDriver")
	@ResponseBody
	public Object getDriver(DriverDim driverDim){
		List<DriverDim> truckDims = scheService.getDriver(driverDim);
		return truckDims;
	}

	//查询承运商信息
	@RequestMapping("/getAllThirdParty")
	@ResponseBody
	public Object getAllThirdParty(ThirdParty thirdParty){
		List<ThirdParty> thirdParties = scheService.getAllThirdParty(thirdParty);
		return thirdParties;
	}

	//查询指定车辆信息
	@RequestMapping("/selectOneCar")
	@ResponseBody
	public Object selectOneCar(Integer truck_id){
		System.out.println(truck_id);
		TruckDim truckDim = scheService.selectOneCar(truck_id);
		System.out.println(truckDim.toString());
		return truckDim;
	}


	//添加调度
	@RequestMapping("/addSchedule")
	@ResponseBody
	public Object addSchedule(Schedule schedule){

		scheService.addSchedule(schedule);
		System.out.println(schedule);
		return "addSchedule";
	}


	//删除调度
	@RequestMapping("/delSchedule")
	@ResponseBody
	public Object delSchedule(Integer sched_id){

		scheService.delSchedule(sched_id);
		return "delSchedule";
	}

	//查询指定车辆
	@RequestMapping("/upSelectOneCar")
	@ResponseBody
	public Object upSelectOneCar(Integer truck_id){
		System.out.println("汽车编号："+truck_id);
		List<TruckDim> upSelectOneCar = scheService.upSelectOneCar(truck_id);
		System.out.println(upSelectOneCar);
		return upSelectOneCar;
	}

	//查询指定司机
	@RequestMapping("/upSelectOneDriver")
	@ResponseBody
	public Object upSelectOneDriver(Integer driver_id){
		System.out.println("司机编号："+driver_id);
		System.out.println( scheService.upSelectOneDriver(driver_id));
		return scheService.upSelectOneDriver(driver_id);
	}

	//查询指定承运商
	@RequestMapping("/upSelectOneCarrier")
	@ResponseBody
	public Object upSelectOneCarrier(Integer third_party_id){
		System.out.println("承运商编号："+third_party_id);
		System.out.println(scheService.upSelectOneCarrier(third_party_id));
		return scheService.upSelectOneCarrier(third_party_id);
	}


	//查询详细货物
	@RequestMapping("/getAllPro")
	@ResponseBody
	public Object getAllPro(Schedule schedule){
		System.out.println(schedule.getPname());
		System.out.println(schedule.getCode());
		System.out.println(schedule.getProvider());
		List<Schedule> allPro = scheService.getAllPro(schedule);

		return allPro;
	}


	//修改调度
	@RequestMapping("/upSchedule")
	@ResponseBody
	public Object upSchedule(Schedule sc){
		System.out.println(sc);
		try {
			scheService.upSchedule(sc);
			Integer[] nums = sc.getNums();
			for (int i = 0; i < nums.length; i++) {
				System.out.println("数量："+nums[i]);
			}
			} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return "up";
	}


	//查询指定货物
	@RequestMapping("/upSelectOnePro")
	@ResponseBody
	public Object upSelectOnePro(Integer sched_id){
		System.out.println("调度编号："+sched_id);
		System.out.println("货物信息："+scheService.upSelectOnePro(sched_id));
		return scheService.upSelectOnePro(sched_id);
	}
	
	
	//提交调度
	@RequestMapping("/submitSchedule")
	@ResponseBody
	public Object submitSchedule(Integer sched_id, String exec_done_flag){
//		System.out.println(exec_done_flag);
		try {
			scheService.submitSchedule(sched_id, exec_done_flag);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "submit";
	}









}
